package com.shujia.bigdata.map;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;

public class Demo4 {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {

        /**
         * 泛型是编译时的类型，只在编译时起作用
         *
         * 泛型：编译时
         * 反射：运行时
         *
         */

        ArrayList<Student> students = new ArrayList<>();

        Student student = new Student();
        students.add(student);

        System.out.println(students);

        /**
         * 通过反射绕过泛型的限制
         */
        //1、获取ArrayList的类对象
        Class listClass = ArrayList.class;
        //2、获取add方法的对象
        Method add = listClass.getMethod("add", Object.class);

        //调用方法
        add.invoke(students, "java");

        System.out.println(students);


    }
}
